package com.ddxz.tool.web.component;

import com.ddxz.tool.web.dto.DdxzException;
import com.ddxz.tool.web.dto.DdxzResponse;
import com.ddxz.tool.web.dto.ErrorStatus;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * class description
 *
 * @author 朱宗刚
 * @version 1.0.0
 * @date 2020/7/26
 */

@Slf4j
@RestControllerAdvice
public class DdxzGlobalException {

    @ExceptionHandler(Exception.class)
    public DdxzResponse exceptionHandler(Exception e) {
        log.error("", e);
        if(e instanceof DdxzException) {
            return ((DdxzException)e).getResponse();
        } else {
            return DdxzResponse.error(ErrorStatus.SYSTEM_ERROR);
        }
    }
}
